#include "./FileOutput.h"

cChar FileOutput::mBuffer [4096];
cChar FileOutput::mTimeBuffer [14];

/**************************************************************
* Other helpful functions                                     *
***************************************************************/
cVoid FileOutput::ClearBuffer() {
	ZeroMemory(FileOutput::mBuffer, 4096 * sizeof(cChar));
}

cVoid FileOutput::ClearTimeBuffer() {
	ZeroMemory(FileOutput::mTimeBuffer, 14 * sizeof(cChar));
}

cVoid FileOutput::Open() {
	this->mOutput.open(LOGS_FILE);
}

cVoid FileOutput::Info(const cChar *print, ...) {
	ClearBuffer();

	va_list args;
	va_start(args, print);
	vsprintf_s(FileOutput::mBuffer, print, args);
	va_end(args);

	this->mOutput<<"INFO: ";
	this->PrintTime();
	this->mOutput<<FileOutput::mBuffer<<std::endl;
}

cVoid FileOutput::PrintTime() {
	SYSTEMTIME time;
	ClearTimeBuffer();

	::GetSystemTime(&time);
	sprintf_s(FileOutput::mTimeBuffer, "[%02i:%02i:%02i] - ", time.wHour, time.wMinute, time.wSecond);
	this->mOutput<<FileOutput::mTimeBuffer;
}

cVoid FileOutput::Debug(const cChar* print, ...) {
	ClearBuffer();

	va_list args;
	va_start(args, print);
	vsprintf_s(FileOutput::mBuffer, print, args);
	va_end(args);
	
	this->mOutput<<"DEBUG: ";
	this->PrintTime();
	this->mOutput<<FileOutput::mBuffer<<std::endl;
}

cVoid FileOutput::Error(const cChar* print, ...) {
	ClearBuffer();

	va_list args;
	va_start(args, print);
	vsprintf_s(FileOutput::mBuffer, print, args);
	va_end(args) ;
	
	this->mOutput<<"ERROR: ";
	this->PrintTime ();
	this->mOutput<<FileOutput::mBuffer<<std::endl;
}

cVoid FileOutput::Warning(const cChar* print, ...) {
	ClearBuffer();

	va_list args;
	va_start(args, print);
	vsprintf_s(FileOutput::mBuffer, print, args);
	va_end(args) ;
	
	this->mOutput<<"WARN: ";
	this->PrintTime ();
	this->mOutput<<FileOutput::mBuffer<<std::endl;
}

cVoid FileOutput::Close() {
	this->mOutput.close();
}